#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    char *ptr[1024];
    int freeStep, freeMin, freeMax, blockSize, numAllocs, j;

    printf("\n");

    int i, *arr;
    scanf("%d", &i);
    arr = (int *) malloc(sizeof(int) * i);
    for (j = 0; j < i; j++) {
        scanf("%d", (arr+j));
    }

    numAllocs = arr[0];
    blockSize = arr[1];

    freeStep = i > 2 ? arr[2] : 1;
    freeMin = i > 3 ? arr[3] : 1;
    freeMax = i > 4 ? arr[4] : 1;

    printf("Initial program break: %10p\n", sbrk(0));
    printf("Allocating %d*%d bytes\n", numAllocs, blockSize);

    for (j = 0; j < numAllocs; j++) {
        ptr[j] = malloc(blockSize);
    }
    printf("Program break is now:%10p\n", sbrk(0));
    printf("Freeing blocks from %d to %d in steps of %d\n", freeMin, freeMax, freeStep);
    for (j = freeMin - 1; j < freeMax; j += freeStep) {
        free(ptr[j]);
    }
    printf("After free(), program break is: %10p\n", sbrk(0));
    exit(1);
}